//原支付密码显示到页面中
$(function(){
	$.ajax({
		url:"/web-adv/judgePayPwd",
		type:"post",
		dataType:"json",
		data:{},
		success:function(json){
			$("#PwdLog").val(json.scorePayPwd);
		}
	});
	//支付密码
	function paycodepat(){
		var paycodeVal=$("#newPsw").val();
		var patPaycode=/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,16}$/;
		if(patPaycode.test(paycodeVal)){
			return true;
		}else{
			return false;
		}
	};
	$("#newPsw").on("blur",function(){
		var result=paycodepat();
		if(!$(this).val()){
			$(this).siblings(".add").html("*必填");
		}else if(result){
			$(this).siblings(".add").html("");
		}else{
			$(this).siblings(".add").html("*6-16位字母、数字和符号(除空格),至少含2种").show();
		}
	});
	$("#againPsw").on("blur",function(){
		var paycodeAgain=$("#againPsw").val();
		var paycode=$("#newPsw").val();
		if(!paycodeAgain){
			$(this).siblings(".add").html("*必填");
		}else if(paycodeAgain!=paycode){
			$(this).siblings(".add").html("*请保证密码一致");
		}else{
			$(this).siblings(".add").html("");
		}
	});
});
$("#submit").click(function(){
	  var PwdLog= $("#PwdLog").val();  //值为0时，跳转到addFastPay.html， 值为1时，跳转到selectBank.html
	  var newPsw = $("#newPsw").val(), againPsw = $("#againPsw").val();
	
        $.ajax({
            type: "POST",
            url: "/web-adv/setPayPwd",
            dataType: "json",
            data: {"payPwd":newPsw},
            success: function (json) {
            	 if (json.status == 1) {
            		 //原支付密码无值
            		 if(PwdLog=="0"){
            			 if(confirm("设置成功！    是否添加快捷支付？")){
                			 window.location.href = "/web-adv/advWeb/views/userCenter/recharge/addFastPay.html?selectedNav=0&navPos=3";
                		 }else{
                			 window.location.href = "/web-adv/advWeb/views/userCenter/recharge/selectBank.html?selectedNav=0&navPos=3";
                		 }
            		 }else{
            			 //原支付密码有值
            			 window.location.href = "/web-adv/advWeb/views/userCenter/recharge/selectBank.html?selectedNav=0&navPos=3";
            		 }
                 }else{
                	 $("#error_psw").html(json.error);
                 }
             },
        });
    
});